package com.newtouch.bxzs.business.train.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.train.model.bo.*;
import com.newtouch.bxzs.business.train.model.vo.UserExaminationQuestionsVO;
import com.newtouch.bxzs.business.train.model.vo.UserExaminationResultVO;
import com.newtouch.bxzs.business.train.model.vo.UserExaminationVO;
import com.newtouch.bxzs.business.train.model.vo.UserWrongCollectionQuestionsVO;
import com.newtouch.bxzs.business.train.service.UserExaminationService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户考试管理Controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/25 9:34</td>
 * <td>dingqianbin</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author dingqianbin
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "用户考试管理")
@RestController
@RequestMapping("/userExaminationController")
@SuppressWarnings("unchecked")
public class UserExaminationController {

    private static final Log logger = LogFactory.getLog(UserExaminationController.class);

    @Autowired
    UserExaminationService userExaminationService;

    @ApiOperation(value = "查询我的考试信息")
    @GetMapping("/getUserExaminationInfo")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/getUserExaminationInfo", userOperationType = 4, userOperationSummary = "查询我的考试信息")
    BaseResponse<UserExaminationInfoBO> getUserExaminationInfo() {
        logger.info("查询我的考试信息");
        return RespGenerator.returnOK(userExaminationService.getUserExaminationInfo());
    }

    @ApiOperation(value = "查询用户考试列表")
    @PostMapping("/getUserExaminationList")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/getUserExaminationList", userOperationType = 4, userOperationSummary = "查询用户考试列表")
    BaseResponse<IPage<UserExaminationBO>> getUserExaminationList(@RequestBody UserExaminationVO userExaminationVO) {
        logger.info("查询我的考试信息");
        return RespGenerator.returnOK(userExaminationService.getUserExaminationList(userExaminationVO));
    }

    @ApiOperation(value = "参加考试返回考题")
    @PostMapping("/getUserExaminationQuestions")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/getUserExaminationQuestions", userOperationType = 4, userOperationSummary = "参加考试返回考题")
    BaseResponse<UserJoinExaminationInfoBO> getUserExaminationQuestions(@RequestBody UserExaminationQuestionsVO userExaminationQuestionsVO) {
        logger.info("参加考试返回考题");
        return RespGenerator.returnOK(userExaminationService.getUserExaminationQuestions(userExaminationQuestionsVO));
    }

    @ApiOperation(value = "答题信息提交")
    @PostMapping("/updateUserExaminationResult")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/updateUserExaminationResult", userOperationType = 3, userOperationSummary = "答题信息提交")
    BaseResponse<Integer> updateUserExaminationResult(@RequestBody UserExaminationResultVO userExaminationResultVO) {
        logger.info("答题信息提交");
        return RespGenerator.returnOK(userExaminationService.updateUserExaminationResult(userExaminationResultVO));
    }

    @ApiOperation(value = "答题结束提交")
    @PostMapping("/endOfAnswer")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/endOfAnswer", userOperationType = 3, userOperationSummary = "答题结束提交")
    BaseResponse<String> endOfAnswer(@RequestBody UserExaminationResultVO userExaminationResultVO) {
        logger.info("答题结束提交");
        return RespGenerator.returnOK(userExaminationService.endOfAnswer(userExaminationResultVO));
    }

    @ApiOperation(value = "查询错题/收藏题列表")
    @PostMapping("/getWrongCollectionQuestions")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/getWrongCollectionQuestions", userOperationType = 4, userOperationSummary = "查询错题/收藏题列表")
    BaseResponse<IPage<UserWrongCollectionQuestionsBO>> getWrongCollectionQuestions(@RequestBody UserWrongCollectionQuestionsVO userWrongCollectionQuestionsVO) {
        logger.info("查询错题/收藏题列表");
        return RespGenerator.returnOK(userExaminationService.getWrongCollectionQuestions(userWrongCollectionQuestionsVO));
    }

    @ApiOperation(value = "查询试题详情信息")
    @GetMapping("/getQuestionInfo")
    @MyLog(systemFunctionName = "用户考试管理", systemFunctionUrl = "/userExaminationController/getQuestionInfo", userOperationType = 4, userOperationSummary = "查询试题详情信息")
    BaseResponse<UserQuestionBO> getQuestionInfo(@RequestParam(value = "examinationQuestionsId")  @ApiParam(value = "试题ID") String examinationQuestionsId) {
        logger.info("查询试题详情信息");
        return RespGenerator.returnOK(userExaminationService.getQuestionInfo(examinationQuestionsId));
    }
}
